<template>
    <div class="newsInfo-container">
        <h1 class="title">{{newsinfo.title}}</h1>
        <p class="subtitle">
            <span>发表时间:{{newsinfo.add_time | dataFormat}}</span>
            <span>次数: {{newsinfo.click}}次</span>
        </p>
        <hr>

        <div class="container" v-html="newsinfo.content"></div>


        <!-- 评论区 -->
        <comment-box :id="this.id"></comment-box>
    </div>
</template>
<script>
import { getnewsinfo } from "@/api";
import { Toast } from "mint-ui";

import comment  from "../subcomponents/comment.vue";
export default {
    data(){
        return {
            id:this.$route.params.id,
            newsinfo:{}
        }
    },
    created(){
        this.init();
    },
    methods:{
        init(){
            getnewsinfo(this.id).then(res=>{
                console.log(res);
                if(res.status===200){
                    this.newsinfo=res.data.message[0];
                }else{
                    Toast('获取新闻失败')
                }
            });
        }       
    },

    components:{
        "comment-box":comment
    }
}
</script>
<style lang="less" scoped>
.newsInfo-container{
    padding:0 4px;
    .title{
        text-align: center;
        font-size: 16px;
        margin:16px 0;
        color:red;
    }
    .subtitle{
        font-size: 13px;
        color:#226aff;
        display:flex;
        justify-content: space-between;
    }

    .container{
        img{
            display: block;
            width:100%;
        }
    }
}
</style>
